﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace ChromaticQFX
{
    public class QFXTransaction
    {
        private string _TransactionType;
        [Description("Transaction Type")]
        public string TransactionType { get { return _TransactionType; } set { _TransactionType = value; } }

        private DateTime _DatePosted;
        [Description("Date Posted")]
        public DateTime DatePosted { get { return _DatePosted; } set { _DatePosted = value; } }

        private Decimal _TransactionAmount;
        [Description("Transaction Amount")]
        public Decimal TransactionAmount { get { return _TransactionAmount; } set { _TransactionAmount = value; } }

        private string _FitID;
        [Description("Unique Transaction ID")]
        public string FitID { get { return _FitID; } set { _FitID = value; } }

        private string _Name;
        [Description("Transaction Name")]
        public string Name { get { return _Name; } set { _Name = value; } }

        private string _Memo;
        [Description("Transaction Memo")]
        public string Memo { get { return _Memo; } set { _Memo = value; } }

        private string _Category = "";
        [Description("Category of the transaction")]
        public string Category { get { return _Category; } set { _Category = value; } }

        public QFXTransaction()
        {
        }

        public QFXTransaction(string TransactionType, DateTime DatePosted, Decimal TransactionAmount,
            string FitID, string Name, string Memo)
        {
            this.TransactionType = TransactionType;
            this.DatePosted = DatePosted;
            this.TransactionAmount = TransactionAmount;
            this.FitID = FitID;
            this.Name = Name;
            this.Memo = Memo;
        }

        public override string ToString()
        {
            return Name;
        }
    }

    public class TransactionComparer : IComparer<QFXTransaction>
    {
        public int Compare(QFXTransaction trans1, QFXTransaction trans2)
        {
            // if a value is compared to itself you must return 0
            if (trans1 == trans2) return 0;

            if (trans1.DatePosted == trans2.DatePosted)
            {
                if (trans1.Name == "ChromaticReconcile") return -1;
                if (trans2.Name == "ChromaticReconcile") return 1;

                return 0;
            }

            return trans1.DatePosted.CompareTo(trans2.DatePosted);
        }

    }

}
